package cn.donting.jme.expansion.builder.mesh;

import cn.donting.jme.EditorContent;
import cn.donting.jme.event.EditorEventBus;
import cn.donting.jme.expansion.attribute.Attribute;
import cn.donting.jme.expansion.attribute.ValueChangeListener;
import cn.donting.jme.expansion.attribute.lmpl.FloatAttribute;
import cn.donting.jme.expansion.attribute.lmpl.IntegerAttribute;
import cn.donting.jme.expansion.attribute.lmpl.Vector3fAttribute;
import cn.donting.jme.ioc.Bean;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;

import javax.swing.*;
import java.util.List;

@Bean
public class SphereAttributeBuilder implements MeshAttributeBuilder<Sphere> {
    @Override
    public boolean isHandle(Object o) {
        return o instanceof Sphere;
    }

    @Override
    public Sphere newInstance() {
        return new Sphere(10, 10, 0.5f);
    }

    @Override
    public Icon getIcon(int size) {
        return new FlatSVGIcon("icon/sphere.svg", size, size);
    }

    @Override
    public void attribute(List<Attribute> attributes, Sphere mesh) {
        //int zSamples, int radialSamples, float radius
        IntegerAttribute zSamples = new IntegerAttribute("zSamples: ");
        zSamples.setValue(mesh.getZSamples());
        zSamples.setMixValue(3);
        zSamples.setTip("The number of samples along the Z.");
        zSamples.setValueChangeListener(true,newValue -> {
            mesh.updateGeometry(newValue, mesh.getRadialSamples(), mesh.getRadius());
            mesh.updateBound();
        });
        attributes.add(zSamples);
        IntegerAttribute radialSamples = new IntegerAttribute("radialSamples: ");
        radialSamples.setValue(mesh.getRadialSamples());
        radialSamples.setTip("The number of samples along the radial.");

        radialSamples.setMixValue(0);
        radialSamples.setValueChangeListener(true,newValue -> {
            mesh.updateGeometry(mesh.getZSamples(), newValue, mesh.getRadius());
            mesh.updateBound();
        });
        attributes.add(radialSamples);

        FloatAttribute radius = new FloatAttribute("半径: ");
        radius.setValue(mesh.getRadius());
        radius.setTip("半径");
        radius.setMinValue(0);
        radius.setValueChangeListener(true,newValue -> {
            mesh.updateGeometry(mesh.getZSamples(), mesh.getRadialSamples(), newValue);
            mesh.updateBound();
        });
        attributes.add(radius);

    }

    @Override
    public String getName() {
        return "球";
    }
}
